﻿using System.Drawing;
using System.Drawing.Drawing2D;
using System.Web;
using System.Web.UI.WebControls;

namespace VotanetWebSite.Classes
{
    public sealed class CustomizeControl
    {
        public static Bitmap ResizePicture(HttpPostedFile f)
        {
            Bitmap originalBMP = new Bitmap(f.InputStream);

            int thumbnail = 150;
            int newWidth = 0, newHeight = 0;
            if (originalBMP.Width > originalBMP.Height)
            {
                newWidth = thumbnail;
                newHeight = originalBMP.Height * thumbnail / originalBMP.Width;
            }
            else
            {
                newWidth = originalBMP.Width * thumbnail / originalBMP.Height;
                newHeight = thumbnail;
            }

            Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
            Graphics grafic = Graphics.FromImage(newBMP);

            grafic.SmoothingMode = SmoothingMode.AntiAlias;
            grafic.InterpolationMode = InterpolationMode.HighQualityBicubic;
            grafic.CompositingQuality = CompositingQuality.HighQuality;
            grafic.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
            return newBMP;

        }

        public static Bitmap ResizePicture(FileUpload f)
        {
            Bitmap originalBMP = new Bitmap(f.FileContent);

            int thumbnail = 150;
            int newWidth = 0, newHeight = 0;
            if (originalBMP.Width > originalBMP.Height)
            {
                newWidth = thumbnail;
                newHeight = originalBMP.Height * thumbnail / originalBMP.Width;
            }
            else
            {
                newWidth = originalBMP.Width * thumbnail / originalBMP.Height;
                newHeight = thumbnail;
            }

            Bitmap newBMP = new Bitmap(originalBMP, newWidth, newHeight);
            Graphics grafic = Graphics.FromImage(newBMP);

            grafic.SmoothingMode = SmoothingMode.AntiAlias;
            grafic.InterpolationMode = InterpolationMode.HighQualityBicubic;
            grafic.CompositingQuality = CompositingQuality.HighQuality;
            grafic.DrawImage(originalBMP, 0, 0, newWidth, newHeight);
            return newBMP;

        }
        
    }
}